<template>
  <form id="form1">
    <div id="container">
      <div class="content">
        <div class="tit">
          <a>首页</a>&gt;
          <a>分支机构</a>&gt;
          <a></a>
        </div>
        <div class="news">
          <div class="about_r">
            <div class="submenu_m">
              <a v-for="item in list" @click="branchDetail(item)"
                :class="item.name == currentObj.name ? 'current' : ''">{{item.name}}</a>
            </div>
            <div class="newsinfo">
              <div class="fenzhi">
                <div class="fenzhitop">
                  <h1>{{currentObj.name}}</h1>
                </div>
                <div class="infobox">
                  <div class="zuixintit">
                    <h2>简介</h2>
                  </div>
                  <p class="MsoNormal" style="text-indent: 42pt; text-align: justify;">
                    <span style="font-size: 14pt; font-family: 仿宋; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">
                      {{currentObj.info}}
                    </span>
                  </p>
                </div>
                <div class="zuixintit">
                  <h2>主要负责人</h2>
                </div>
                <div id="person" class="person">
                  <div class="type" v-for="item in currentObj.list">
                    <div class="typeTitle">{{item.name}}</div>
                    <a v-for="person in item.personList"
                      :href="'/newsview?type=2&id='+person.id">
                      <dl>
                        <dt>
                          <img :src="person.img">
                        </dt>
                        <dd>{{person.name}}</dd>
                        <dd class="personUnit">{{person.title}}</dd>
                      </dl>
                    </a>
                  </div>
                </div>
                <div class="zuixintit">
                  <h2>联系方式</h2>
                </div>
                <div id="unitNewsList">
                  <p v-if="currentObj.contactName"
                    class="MsoNormal" align="left">
                    <span style="font-size: 14pt; font-family: 仿宋; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">
                      联系人：{{currentObj.contactName}}
                    </span>
                  </p>
                  <p v-if="currentObj.phone"
                    class="MsoNormal" align="left">
                    <span style="font-size: 14pt; font-family: 仿宋; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">
                      联系电话：{{currentObj.phone}}
                    </span>
                  </p>
                  <p v-if="currentObj.email"
                    class="MsoNormal" align="left">
                    <span style="font-size: 14pt; font-family: 仿宋; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">
                      电子邮箱：{{currentObj.email}}
                    </span>
                  </p>
                  <p v-if="currentObj.address"
                    class="MsoNormal" align="left">
                    <span style="font-size: 14pt; font-family: 仿宋; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">
                      地址：{{currentObj.address}}
                    </span>
                  </p>
                  <p v-if="currentObj.website"
                    class="MsoNormal" align="left">
                    <span style="font-size: 14pt; font-family: 仿宋; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">
                      网站：{{currentObj.website}}
                    </span>
                  </p>

                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </form>
</template>

<script>
import Data from '@/api/data'

export default {
  name: 'Index',
  props:{
    layout: String
  },
  data() {
    return {
      list:[],
      currentObj:[],




      dictType: "PERSON_TYPE",
      collegeList: [],

      name: "",

    }
  },
  watch: {
    month: {

    }

  },
  computed: {
  },
  created() {
    this.branchList()
  },
  methods: {
    branchList() {
      var _this = this
      Data.get("/branch", {size:30,type:"BRANCH"}).then(res=>{
        _this.list = res.list
        if(res.list && res.list.length > 0) {
          _this.branchDetail(res.list[0])
        }
        console.log(_this.list)
      })
    },
    branchDetail(item) {
      this.currentObj = item
      if(item.list) {
        return
      }

      //请求负责人
      var data = {type: this.dictType, parent: item.id};
      Data.get("/dictionary", data).then(async res=>{
        var list = res.list
        if(res.list && res.list.length > 0) {
          //循环
          for(var i = 0;i<list.length;i++) {
            var personList = await this.personLoad(list[i]);
            list[i]["personList"] = personList
          }
        }
        this.$set(this.currentObj, "list", list)
      })
    },
    async personLoad(item) {
      var list = item.value.split(";");
      var ids = []
      for(var i = 0; i < list.length; i++ ) {
        var id = list[i].split(":")[0]
        if(id) {
          ids.push(id)
        }
      }
      if(ids.length > 0) {
        var res = await Data.get("/person/listByIds", {ids: ids.join(",")});
        return res;
      }
      return ""
    },

  }
}
</script>

<style lang="scss" scoped>
@import "~@/styles/new_files_m/bootstrap.min.css";
@import "~@/styles/new_files_m/iconfont.css";
@import "~@/styles/new_files_m/comm.css";
@import "~@/styles/new_files_m/info.css";
</style>
